home *** CD-ROM | disk | FTP | other *** search
- unit UMemF1;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- E_MemMap, Buttons, StdCtrls, Mask, ComCtrls;
-
- type
- TForm1 = class(TForm)
- SpeedButton1: TSpeedButton;
- SpeedButton2: TSpeedButton;
- Label1: TLabel;
- NdxEdit: TMaskEdit;
- SpeedButton3: TSpeedButton;
- Label2: TLabel;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure SpeedButton1Click(Sender: TObject);
- procedure SpeedButton2Click(Sender: TObject);
- procedure SpeedButton3Click(Sender: TObject);
- private
- { Private declarations }
- EMemMap : TEFileMap;
- CurPage : Cardinal;
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
- Const
- MaxArrSize = 16384;
- Type
- IntArr = Array[0..MaxArrSize-1] Of Integer;
- IntArrPtr = ^IntArr;
-
- procedure TForm1.FormCreate(Sender: TObject);
- Var
- I,J : Integer;
- IArr : IntArrPtr;
- F : File;
- begin
- EMemMap:=TEFileMap.Create(Self);
- If NOT EMemMap.CreateMutex('DAVESMUTEXF') then
- EMemMap.RaiseMappingException;
- AssignFile(F,'DAVEJUNK.DAT');
- If NOT FileExists('DAVEJUNK.DAT') then
- begin
- New(IArr);
- Rewrite(F,1);
- For I:=1 to 3 do
- begin
- For J:=1 to MaxArrSize do
- IArr^[J-1]:=J+((I-1)*MaxArrSize);
- BlockWrite(F,IArr^[0],SizeOf(IntArr));
- end;
- Dispose(IArr);
- end
- else
- Reset(F,1);
- EMemMap.MemSize:=FileSize(F);
- CloseFile(F);
- Caption:='Int Array [0..'+IntToStr(MaxArrSize*3-1)+']';
- If NOT EMemMap.MapExisting('DAVESMAPF',SizeOf(IntArr)) then
- If NOT EMemMap.FCreateMemMap('DAVEJUNK.DAT','DAVESMAPF',SizeOf(IntArr)) then
- EMemMap.RaiseMappingException;
- CurPage:=0;
- end;
-
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- EMemMap.Free;
- end;
- procedure TForm1.SpeedButton1Click(Sender: TObject);
- Var
- AnInt : Integer;
- begin
- AnInt:=StrToInt(NdxEdit.Text);
- If (AnInt>=0) AND (AnInt<MaxArrSize) then
- begin
- EMemMap.EnterCriticalSection;
- Try
- AnInt:=IntArrPtr(EMemMap.MemMap)^[AnInt];
- Finally
- EMemMap.LeaveCriticalSection;
- end;
- MessageDlg(IntToStr(AnInt),mtInformation,[mbOk],0);
- end;
- end;
-
- procedure TForm1.SpeedButton2Click(Sender: TObject);
- Var
- Ndx : Integer;
- AnInt : Integer;
- AValue : String;
- begin
- Ndx:=StrToInt(NdxEdit.Text);
- If (Ndx>=0) AND (Ndx<MaxArrSize) then
- begin
- EMemMap.EnterCriticalSection;
- Try
- AnInt:=IntArrPtr(EMemMap.MemMap)^[Ndx];
- AValue:=IntToStr(AnInt);
- InputQuery('Get Value','NewValue',AValue);
- AnInt:=StrToInt(AValue);
- IntArrPtr(EMemMap.MemMap)^[Ndx]:=AnInt;
- Finally
- EMemMap.LeaveCriticalSection;
- end;
- end;
- end;
-
-
- procedure TForm1.SpeedButton3Click(Sender: TObject);
- Var
- APage : String;
- AInt : Integer;
- begin
- APage:=IntToStr(CurPage);
- If InputQuery('Get Next Page (0..'+IntToStr(EMemMap.MaxSeeks)+')','Page Number',APage) then
- begin
- AInt:=StrToInt(APage);
- If AInt<>Curpage then
- begin
- CurPage:=AInt;
- If NOT EMemMap.Seek(CurPage) then
- EMemMap.RaiseMappingException;
- end;
- end;
- end;
-
- end.
-